//
//  LGRecoveryDetailContent.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/8/8.
//

#import "LGRecoveryDetailContent.h"

@interface LGRecoveryDetailContent()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIButton *sureBtn;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
@end

@implementation LGRecoveryDetailContent

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0];
        [self addSubview:self.baseView];
        [self.baseView addSubview:self.titleLabel];
        [self.baseView addSubview:self.sureBtn];
        [self.baseView addSubview:self.contentLabel];
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.baseView).offset(viewPix(70));
            make.left.equalTo(self.baseView).offset(viewPix(20));
            make.right.equalTo(self.baseView).offset(-viewPix(10));
        }];
    }
    return self;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
}

-(void)setContent:(NSString *)content{
    _content = content;
    CGFloat height = [content textHeightWithFont:LGFont(16) maxWidth:Screen_W-viewPix(30)];
    self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, height+viewPix(150));
    self.contentLabel.text = content;
    [UIView animateWithDuration:0.4 animations:^{
        CGFloat height = self.baseView.size.height;
        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.5];
        self.baseView.frame = CGRectMake(0, Screen_H-height+viewPix(15), Screen_W, height);
    }];
}

-(void)sureBtnAction{
    [UIView animateWithDuration:0.4 animations:^{
        CGFloat height = self.baseView.size.height;
        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0];
        self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, height);
        
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}


-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_H, Screen_W, viewPix(450))];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:2];
        _titleLabel.frame = CGRectMake(viewPix(60), viewPix(14), Screen_W-viewPix(120), viewPix(42));
    }
    return _titleLabel;
}

-(UIButton *)sureBtn{
    if(!_sureBtn){
        _sureBtn = [UIButton buttonWithTitle:@"确定" titleFont:LGFontWeight(16, UIFontWeightSemibold) textColor:@"#429BFF" imageName:@""];
        _sureBtn.frame = CGRectMake(Screen_W-viewPix(55), viewPix(20), viewPix(35), 22+viewPix(8));
        [_sureBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureBtn;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel;
}


@end
